Skip to content

Conversation

@rlawnsrl123
Copy link

  • Add a dedicated API page for Series.__invert__() so users searching for “invert/~” can find it.
  • Clarify boolean vs integer meaning and NA propagation semantics (incl. Arrow-backed boolean).
  • Add a one-line cross-link from the Boolean indexing guide.
  • Docs-only; no behavior change.

Closes #62516.

@rlawnsrl123 rlawnsrl123 marked this pull request as ready for review October 9, 2025 18:15
@mroeschke mroeschke requested a review from rhshadrach October 10, 2025 17:50
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Comment on lines 112 to 115
.. toctree::
:maxdepth: 1

api/pandas.Series.__invert__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we follow the rest of the API documentation here:

.. autosummary::
   :toctree: api/

   Series.__invert__

@@ -0,0 +1,53 @@
.. currentmodule:: pandas
Copy link
Member

@rhshadrach rhshadrach Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the request above, this file can be removed. Add anything necessary to the docstring of __invert__ instead.

Comment on lines +814 to +815
For toggling boolean masks with the ``~`` operator, see
:meth:`pandas.Series.__invert__`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ is already mentioned in the paragraph above; I think this can be removed.

Comment on lines +7342 to +7344
# at bottom of pandas/core/series.py (after class Series ...)
from pandas.core.ops.docstrings import _doc_series_invert
Series.__invert__.__doc__ = _doc_series_invert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can instead add the following to series.py in the Series class:

def __invert__(self) -> Self:
    return super().__invert__()

Then we can add the docstring there. But I would like a 2nd opinion here, cc @mroeschke.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's best to keep docstring with the function definitions

See Also
--------
Series.__and__, Series.__or__, Series.__xor__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you separate out to one line each, with a short description. See other docstrings in this file for examples.

@rhshadrach rhshadrach added Docs Series Series data structure labels Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Series Series data structure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: Missing documentation for Series.__invert__() (~ operator)

3 participants